/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.src.ptit.javatraining.huynh.btvn1;

/**
 *
 * @author user
 */
public class Baitap8 {

    private static int check(String s) {
        int a[] = new int[8];
        for (int i = 0; i < s.length(); i++) {
            String s2;
            s2 = Character.toString(s.charAt(i));
            int m = Integer.parseInt(s2);
            a[i] = m;
            if (i > 0) {
                if (a[i] < a[i - 1]) {
                    return 0;
                }
            }
            if (Baitap1.isPrime(m) == false) {
                return 0;
            }
        }
        if (Baitap1.isPrime(Integer.parseInt(s)) == true) {
            return 1;
        }
        return 0;
    }

    public static void main(String[] args) {
        int min = (int) Math.pow(10, 6);
        int max = (int) Math.pow(10, 7);
        for (int i = min; i <= max; i++) {
            String s;
            s = String.valueOf(i);
            if (check(s) == 1) {
                System.out.println(s);
            }
        }
    }
}
